from collections import OrderedDict
from apps.centents.models import Content,ContentCategory
from apps.centents.utils import get_channel_dict
from django.shortcuts import render

from django.views import View
from apps.goods.models import GoodsChannel, GoodsCategory


class IndexView(View):
    """
    1.先通过channel外键获取分类组id
    2.在通过channel外键获取一级目录
    3.通过一级目录获取二级目录，通过二级目录获取三级
    4.拼前端格式
    """
    def get(self,request):
        """
        获取首页广告
        """
        content_dict = {}
        categroy = ContentCategory.objects.all()
        for cat in categroy:
            content_dict[cat.key]= cat.content_set.order_by("sequence").filter(status= True)
        channel_dict = get_channel_dict()
        context = {
            'categories': channel_dict,
            'contents': content_dict
        }

        return render(request,"index.html",context)